'use strict';
const Index = require('../app/controllers/home/index');

/**
 * 导出模块
 */
module.exports = router => {
  // router.opts = {prefix:'/home'}
  router.get('/', Index.home)
  router.get('/detail/:id', Index.detail)
  router.get('/class', Index.class);
  router.get('/search', Index.search)
  router.get('/sort/type=:id&page=:page&name=:name&by=:by&sort=:sort', Index.sort);
  router.get('/sort/key=:keyword&page=:page&by=:by&sort=:sort', Index.sort);
  router.get('/book/book_id=:id&name=:name', Index.book);
  router.get('/personalset', Index.personalset);
  router.get('/personalset/bindAccount', Index.bindAccount);
  router.get('/read/:comic_id/:chapter_id', Index.read);
  router.get('/discovery', Index.discovery)
  router.get('/mine', Index.mine)
  router.get('/help', Index.help)
  router.get('/login', Index.login)
  router.get('/personalset/bindpage/:type', Index.bindpage)
  router.get('/personalset/modifypage/:type', Index.modifypage)
  router.get('/record_list', Index.record_list)

  // 对非法路由进行处理
  router.get('*', async(ctx) => {
    var data = {
      title: '网站错误提示信息:',
      status: ctx.status + 'ss' || 500,
      message: ctx.message || '服务器出错了。'
    };
    switch(data.status) {
      case 404:
        await ctx.render('default/404', data);
        break;
      case 500:
        await ctx.render('default/500', data);
        break;
      default:
        await ctx.render('default/error', data);
    }
  });

};